package com.ibeeking.found.open.api.feign.fallback;

import com.ibeeking.found.open.api.common.dto.ParkingPlatformDTO;
import com.ibeeking.found.open.api.common.dto.StatisticsCarDTO;
import com.ibeeking.found.open.api.common.dto.TenantParkingInfoDTO;
import com.ibeeking.found.open.api.common.param.ParkingChargeRecordParam;
import com.ibeeking.found.open.api.common.param.ParkingInParam;
import com.ibeeking.found.open.api.common.param.ParkingOrderParam;
import com.ibeeking.found.open.api.common.param.ParkingOutParam;
import com.ibeeking.found.open.api.common.query.ParkingConfigQuery;
import com.ibeeking.found.open.api.common.query.StatisticsCarQuery;
import com.ibeeking.found.open.api.feign.ParkingFeignClient;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class ParkingFeignFallbackFactory implements FallbackFactory<ParkingFeignClient> {
    @Override
    public ParkingFeignClient create(Throwable throwable) {
        return new ParkingFeignClient() {

            @Override
            public ResponseResult<ParkingPlatformDTO> parkingConfig(ParkingConfigQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询停车场配置失败。", null);
            }

            @Override
            public ResponseResult<Boolean> receiveInParkInfo(List<ParkingInParam> params) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，保存入场信息失败。", false);
            }

            @Override
            public ResponseResult<Boolean> receiveOutParkInfo(List<ParkingOutParam> params) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，保存出场信息失败。", false);
            }

            @Override
            public ResponseResult<Boolean> receiveParkOrder(List<ParkingOrderParam> params) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，保存订单信息失败。", false);
            }

            @Override
            public ResponseResult<TenantParkingInfoDTO> queryTenantIdByParkCode(String parkCode) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询停车场所属租户失败。", null);
            }

            @Override
            public ResponseResult<Boolean> receiveParkCharge(List<ParkingChargeRecordParam> params) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，保存收费记录失败。", false);
            }

            @Override
            public ResponseResult<List<StatisticsCarDTO>> statisticsCar(StatisticsCarQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，统计车流失败。", Collections3.emptyList());
            }
        };
    }
}
